// createRouter：创建router实例对象
// createWebHistory：创建history模式的路由
import { createRouter, createWebHistory } from "vue-router";
import SubCategory from "../views/SubCategory/index.vue";
import Detail from "../views/Detail/index.vue";
import CartList from "../views/CartList/index.vue";
import Checkout from "../views/Checkout/index.vue";
import Pay from "../views/Pay/index.vue";
import PayBack from "@/views/Pay/PayBack.vue";
import UserInfo from "@/views/Member/components/UserInfo.vue";
import UserOrder from "@/views/Member/components/UserOrder.vue";
import Member from "@/views/Member/index.vue";

const router = createRouter({
  history: createWebHistory(import.meta.env.BASE_URL),
  routes: [
    {
      path: "/",
      name: "Layout",
      component: () => import("../views/Layout/index.vue"),
      children: [
        {
          // 首页默认显示Layout和Home组件
          path: "",
          name: "Home",
          component: () => import("../views/Home/index.vue"),
        },
        {
          path: "category/:id",
          name: "Category",
          component: () => import("../views/Category/index.vue"),
        },
        {
          path: "category/sub/:id",
          name: "SubCategory",
          component: SubCategory,
        },
        {
          path: "detail/:id",
          name: "Detail",
          component: Detail,
        },
        {
          path: "cartList",
          name: "CartList",
          component: CartList,
        },
        {
          path: "checkout",
          component: Checkout,
        },
        {
          path: "pay",
          component: Pay,
        },
        {
          path: "paycallback", // 注意路径，必须是paycallback
          component: PayBack,
        },
        {
          path: "member",
          component: Member,
          redirect: "/member/user",
          children: [
            {
              path: "user",
              component: UserInfo,
            },
            {
              path: "order",
              component: UserOrder,
            },
          ],
        },
      ],
    },
    {
      path: "/login",
      name: "Login",
      component: () => import("../views/Login/index.vue"),
    },
  ],
  // 路由滚动行为定制
  scrollBehavior: () => ({
    top: 0,
    left: 0,
  }),
});

export default router;
